//
//  RBBaseViewController.m
//  RMMaterialRed
//
//  Created by XBWH on 2024/3/5.
//

#import "RBBaseViewController.h"

@interface RBBaseViewController ()

@end

@implementation RBBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate{
    return NO;
}
- (void)switchUIOrientationWithLaunchScreen:(BOOL)isLaunchScreen{
    if (@available(iOS 16.0, *)) {
           // iOS16新API，让控制器刷新方向，新方向为上面设置的orientations
   #if defined(__IPHONE_16_0)
           [self setNeedsUpdateOfSupportedInterfaceOrientations];
           NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
           UIWindowScene *scene = [array firstObject];
           // 屏幕方向
           UIInterfaceOrientationMask orientation = isLaunchScreen ? UIInterfaceOrientationMaskLandscapeRight : UIInterfaceOrientationMaskPortrait;
           UIWindowSceneGeometryPreferencesIOS *geometryPreferencesIOS = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:orientation];
           // 开始切换
           [scene requestGeometryUpdateWithPreferences:geometryPreferencesIOS errorHandler:^(NSError * _Nonnull error) {
               //NSLog(@"强制%@错误:%@", @"横屏", error);
           }];
   #endif
        } else {
             // iOS16以下
            UIDeviceOrientation willOrientation = isLaunchScreen?UIDeviceOrientationLandscapeRight:UIDeviceOrientationPortrait;
             NSNumber *orientationPortrait = [NSNumber numberWithInteger:willOrientation];
             [[UIDevice currentDevice] setValue:orientationPortrait forKey:@"orientation"];
         }
}

@end
